package cn.edu.neusoft.yuejian4.yuejian_4.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.edu.neusoft.yuejian4.yuejian_4.R;
import cn.edu.neusoft.yuejian4.yuejian_4.adapter.TrainListAdapter;
import cn.edu.neusoft.yuejian4.yuejian_4.javaBean.Train;
import cn.edu.neusoft.yuejian4.yuejian_4.listener.List_TListener;
import cn.edu.neusoft.yuejian4.yuejian_4.listener.TListener;
import cn.edu.neusoft.yuejian4.yuejian_4.model.TrainModel;


/**
 * Created by Lix on 2018/9/30.
 */

public class TrainFragment extends Fragment implements View.OnClickListener{

    private Button lv1,lv2,lv3,lv4;
    private TextView tr_title;
    private RecyclerView recyclerView;
    private View  view;



    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_train,container,false);

        initViews();
        initEvent();
        TrainModel trainModel = new TrainModel();
        trainModel.allTrain(alllistener);
        return view;

    }

    List_TListener<Train> alllistener = new List_TListener<Train>() {
        @Override
        public void onResponse(List<Train> list) {
            TrainListAdapter trainListAdapter = new TrainListAdapter(getContext(),list);
            recyclerView.setAdapter(trainListAdapter);
        }

        @Override
        public void onFail(String msg) {

        }
    };


    private void initEvent() {
        lv1.setOnClickListener(this);
        lv2.setOnClickListener(this);
        lv3.setOnClickListener(this);
        lv4.setOnClickListener(this);
    }

    private void initViews() {
        recyclerView = (RecyclerView)view.findViewById(R.id.rv_train);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        lv1 = (Button) view.findViewById(R.id.peixun_level1);
        lv2 = (Button) view.findViewById(R.id.peixun_level2);
        lv3 = (Button)view.findViewById(R.id.peixun_level3);
        lv4 = (Button) view.findViewById(R.id.peixun_level4);
        tr_title = (TextView)view.findViewById(R.id.tr_title);
        tr_title.setText("体育培训");
    }

    @Override
    public void onClick(View v) {
        TrainModel trainModel = new TrainModel();
        switch (v.getId()){
            case R.id.peixun_level1:
                trainModel.rumenTrain(alllistener);
                tr_title.setText("体育培训-入门");
                break;
            case R.id.peixun_level2:
                trainModel.cainiaoTrain(alllistener);
                tr_title.setText("体育培训-菜鸟");
                break;
            case R.id.peixun_level3:
                trainModel.jinjieTrain(alllistener);
                tr_title.setText("体育培训-进阶");
                break;
            case R.id.peixun_level4:
                trainModel.allTrain(alllistener);
                tr_title.setText("体育培训");
                break;
        }
    }
}
